{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bb9b1155",
   "metadata": {},
   "source": [
    "# 用户需求分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b865f737",
   "metadata": {},
   "source": [
    "### 1.用户是谁？\n",
    "> 1.去菜市场买菜的年轻人；  \n",
    "> 2.牙牙学语认识蔬菜的小朋友；  \n",
    "> 3.想对果蔬有了解的人；   \n",
    "\n",
    "### 2.需求场景是怎么样的？  \n",
    "> 1.去菜市场买菜;    \n",
    "> 2.闲聊与他人分享果蔬时；  \n",
    "> 3.在课堂时；\n",
    "\n",
    "### 3.用户遇到的问题是什么？\n",
    "> 1.1.去菜市场买菜但是却不知道这个蔬菜叫什么名字；  \n",
    "> 2.觉得某一个不常见的果蔬很合胃口，想跟别人分享，却不知道其名称时；  \n",
    "> 3.和他人聊起果蔬，却不知道；  \n",
    "\n",
    "### 4.用户想要解决的实际需求是什么？  \n",
    "> 1.想要知道果蔬的名字  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "483a1503",
   "metadata": {},
   "source": [
    "# 可行性的运用：果蔬辨别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3620b914",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.6aa0ef58533e1f69a4ac410a174a4a0d.315360000.1965019893.282335-25904767', 'expires_in': 2592000, 'session_key': '9mzdWTk5OphX1O2O0ibaJRJGu6n6SJjXcNeNRGhs6/xvKfu8ScEVGC8GvMDupQ/f6Bwn6x5iiTwsVFmbdv5g/djTldjtLg==', 'access_token': '24.bc72b21ca21601eca58848a143cfb563.2592000.1652251893.282335-25904767', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': '52544013bd5a6dfb9dd237d060bcdef4'}\n"
     ]
    }
   ],
   "source": [
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=pvh7wPOgAIre2V2orb9XtF3g&client_secret=ly3SvdsltQenkt0haP9LGcNSG6e3wCSR'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e6bdbb10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.6aa0ef58533e1f69a4ac410a174a4a0d.315360000.1965019893.282335-25904767',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdWTk5OphX1O2O0ibaJRJGu6n6SJjXcNeNRGhs6/xvKfu8ScEVGC8GvMDupQ/f6Bwn6x5iiTwsVFmbdv5g/djTldjtLg==',\n",
       " 'access_token': '24.bc72b21ca21601eca58848a143cfb563.2592000.1652251893.282335-25904767',\n",
       " 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online',\n",
       " 'session_secret': '52544013bd5a6dfb9dd237d060bcdef4'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a5ae1328",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.bc72b21ca21601eca58848a143cfb563.2592000.1652251893.282335-25904767'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "access_token = response.json()['access_token']\n",
    "access_token"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d21847c",
   "metadata": {},
   "source": [
    "## 用户上传果蔬图片，了解它叫什么"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fb180b44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result_num': 5, 'result': [{'score': 0.4545321, 'name': '非果蔬食材'}, {'score': 0.15273374, 'name': '胡萝卜'}, {'score': 0.13005671, 'name': '黄瓜'}, {'score': 0.104294516, 'name': '萝卜'}, {'score': 0.048622187, 'name': '土豆'}], 'log_id': 1513411378506046783}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('shucai.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = access_token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f14955b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
